<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      /* const nums = [2, 5, 34, 65, 21];
      function* createIterator(arr) {
        for (const item of arr) {
          yield item;
        }
      }

      const generator = createIterator(nums);
      console.log(generator.next());
      console.log(generator.next());
      console.log(generator.next());
      console.log(generator.next()); */

      function* getfeiboIterator() {
        let pre1 = 1,
          pre2 = 1,
          n = 1;
        while (true) {
          if (n <= 2) {
            yield 1;
          } else {
            let newVal = pre1 + pre2;
            yield newVal;
            pre2 = pre1;
            pre1 = newVal;
          }
          n++;
        }
      }

      const iterator = getfeiboIterator();
    </script>
  </body>
</html>
